<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml">

	<head>
		<meta charset="utf-8">
		<title>小K服务</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link rel="shortcut icon" href="../../../static/favicon.ico" th:href="@{/favicon.ico}">
        <link rel="stylesheet" type="text/css" href="../../../static/mui/css/mui.min.css" th:href="@{/mui/css/mui.min.css}" />
		<style type="text/css">
			.area {
				margin: 20px auto 0px auto;
			}
			
			.mui-input-group {
				margin-top: 10px;
			}
			
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			
			.mui-input-group label {
				width: 22%;
			}
			
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			
			.mui-content-padded {
				margin-top: 25px;
			}
			
			.mui-btn {
				padding: 10px;
			}
			
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
			
			.spliter {
				color: #bbb;
				padding: 0px 8px;
			}
			
			.oauth-area {
				position: absolute;
				bottom: 20px;
				left: 0px;
				text-align: center;
				width: 100%;
				padding: 0px;
				margin: 0px;
			}
			
			.oauth-area .oauth-btn {
				display: inline-block;
				width: 50px;
				height: 50px;
				background-size: 30px 30px;
				background-position: center center;
				background-repeat: no-repeat;
				margin: 0px 20px;
				/*-webkit-filter: grayscale(100%); */
				border: solid 1px #ddd;
				border-radius: 25px;
			}
			
			.oauth-area .oauth-btn:active {
				border: solid 1px #aaa;
			}
			
			.oauth-area .oauth-btn.disabled {
				background-color: #ddd;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">小K服务平台</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group" v-if="loginType === 0">
				<div class="mui-input-row">
					<label>学号</label>
					<input v-model="loginBean1.stuId" type="text" class="mui-input-clear mui-input" placeholder="请输入学号">
				</div>
				<div class="mui-input-row">
					<label>姓名</label>
					<input v-model.trim="loginBean1.name" type="text" class="mui-input-clear mui-input" placeholder="请输入姓名">
				</div>
			</form>
            <form class="mui-input-group" v-else>
                <div class="mui-input-row">
                    <label>学号</label>
                    <input v-model="loginBean2.stuId" type="text" class="mui-input-clear mui-input" placeholder="请输入学号">
                </div>
                <div class="mui-input-row">
                    <label>密码</label>
                    <input v-model.trim="loginBean2.password" type="password" class="mui-input-clear mui-input" placeholder="请输入登录密码">
                </div>
            </form>
			<div class="mui-content-padded">
				<button v-on:click="login($event)" class="mui-btn mui-btn-block mui-btn-primary">登录系统</button>
                <div class="link-area"><a href="javascript:void(0)" v-on:click="chanageLoginType">用【{{loginTypeName[loginType]}}】登录</a>
                </div>
			</div>
            <div class="mui-content-padded" th:utext="${application.loginInfo}">
                <p>Hello，欢迎使用小K服务，本站不提供注册功能。您可以联系管理员：lscode@163.com</p>
            </div>
		</div>
		<script src="../../../static/mui/js/mui.min.js" th:src="@{/mui/js/mui.min.js}"></script>
		<script src="../../../static/plugins/vuejs/vue.min.js" th:src="@{/plugins/vuejs/vue.min.js}" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">

                var app = new Vue({
                    el: '.mui-content',
                    data: {
                        loginBean1:{
                            stuId:"",
                            name:""
                        },
                        loginBean2:{
                            stuId:"",
                            password:""
                        },
                        loginType:0,
                        loginTypeName:["学号-密码","学号-姓名"]
                    },
                    methods:{
                        chanageLoginType:function () {
                            if (this.loginType === 0) {
                                this.loginType = 1
                            }else {
                                this.loginType = 0;
                            }
                        },
                        login:function(evn){
                            mui(evn.target).button('loading');
                            var bean;
                            if(this.loginType === 0){//用学号-姓名登录
                                bean = this.loginBean1;
                                if(bean.stuId.length === 0){
                                    mui.toast("学号不能为空");
                                    mui(evn.target).button('reset');
                                    return false;
                                }
                                if(bean.name.length === 0){
                                    mui.toast("姓名不能为空");
                                    mui(evn.target).button('reset');
                                    return false;
                                }
                            }else{
                                bean = this.loginBean2;
                                if(bean.stuId.length === 0){
                                    mui.toast("学号不能为空");
                                    mui(evn.target).button('reset');
                                    return false;
                                }
                                if(bean.password.length === 0){
                                    mui.toast("密码不能为空");
                                    mui(evn.target).button('reset');
                                    return false;
                                }
                            }

                            mui.ajax({
                                type:"post",
                                data:bean,
                                url:"userLogin",
                                async:true,
                                dataType:"json",
                                success:function(data){
                                    if(data.code === 0){
                                        mui.toast(data.msg);
                                        mui.openWindow({
                                            url: "user/index",
                                            show: {
                                                autoShow: true
                                            }
                                        });
                                        mui(evn.target).button('reset');
                                    }else {
                                        mui.toast(data.msg);
                                        mui(evn.target).button('reset');
                                    }
                                },
                                error:function(){
                                    mui.toast("加载错误");
                                    mui(evn.target).button('reset');
                                }
                            });
//						window.location.href="index.html";
                        }
                    },
                    mounted:function () {
                        mui.init();
                    }
                });

		</script>
	</body>

</html>